package com.chen.pspms.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Package: com.hqq.web
 * User: 何芊芊
 * Email: heqianqian1@jd.com
 * Date: 2017/11/6
 * Time: 18:01
 * Description:
 */
@Controller
public class IndexController {


    @RequestMapping("/index")
    public String index() {
        return "home";
    }

    @RequestMapping("/main")
    public String main(HttpServletRequest request) {
        HttpSession session = request.getSession();
        //从服务器获取session username
        String username = (String) session.getAttribute("username");
        //如果sessionId存在 用户登录过 就直接登录主页
        if (null != username) {
            return "持证人管理/持证人管理页面";
        } else {
            return "登录/login";
        }
    }

    @RequestMapping(value = "/dologin")
    public String login(HttpServletRequest request) {
        HttpSession session = request.getSession();
        String username = request.getParameter("userInput");
        session.setAttribute("username", username);
        return "redirect:/main";
    }

    @RequestMapping(path = {"/login"}, method = {RequestMethod.GET})
    public String login() {
        return "持证人管理/持证人管理页面";
    }
}